//
// Created by sgyt on 2020/2/1.
//
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>

jmp_buf jmpBuf;

void fun1()
{
    printf("Before fun1...\n");
    longjmp(jmpBuf,1);
    printf("After fun1...\n");
}

void fun2()
{
    printf("Before fun2...\n");
    fun1();
    printf("After fun2...\n");
}

int main(int argc,char *argv[])
{
    int res=0,i = 0;
    //使用setjmp
    res = setjmp(jmpBuf);
    printf("res = [%d]\n",res);
    if(res == 0)
    {
        i++;
        if(i>5)
        {
            exit(0);
        }
        printf("Before  setjmp first call\n");
        fun2();
        printf("After  setjmp first call\n");
    }else{
        printf("this is setjmp second call\n");
    }
    return 0;
}
